package org.ziwei.paipan.biao;

import org.ziwei.paipan.var.DiZhi;
import org.ziwei.paipan.var.StarCode;

/**
 * 支系诸星表
 * 根据出生年地支，定支系诸星宫位
 */
public class ZhiXiZhuXingBiao {

	/**
	 * 命主身主表
	 */
	private static StarCode[] mingZhuBiao = { StarCode.TANLANG, StarCode.JUMEN, StarCode.LUCUN, StarCode.WENQU, StarCode.LIANZHEN, StarCode.WUQU, 
			 StarCode.POJUN, StarCode.WUQU, StarCode.LIANZHEN, StarCode.WENQU, StarCode.LUCUN, StarCode.JUMEN};

	private static StarCode[] shenZhuBiao = { StarCode.HUOXING, StarCode.TIANXIANG, StarCode.TIANLIANG, StarCode.TIANTONG, StarCode.WENCHANG, StarCode.TIANJI, 
				 StarCode.HUOXING, StarCode.TIANXIANG, StarCode.TIANLIANG, StarCode.TIANTONG, StarCode.WENCHANG , StarCode.TIANJI};
	
	/**
	* 根据时辰，返回命主
	* @param dz
	* @return Star
	*/
	public static StarCode anMingZhu(DiZhi dz){
		return mingZhuBiao[dz.ordinal()];
	}
	
	
	/**
	* 根据时辰，返回身主
	* @param dz
	* @return Star
	*/
	public static StarCode anShenZhu(DiZhi dz){
		return shenZhuBiao[dz.ordinal()];
	}
	
	
	/**
	 * 红鸾天喜是两个喜星
	 * 田喜星始终在红鸾星的对宫
	 * 红鸾星由卯宫起子年，逆数到本人生年地支，安红鸾星，对宫安天喜
	 */
	private static DiZhi[] hongLuanBiao = {DiZhi.MAO,DiZhi.YIN,DiZhi.CHOU,DiZhi.ZI,DiZhi.HAI,DiZhi.XU,DiZhi.YOU,DiZhi.SHEN,DiZhi.WEI,DiZhi.WU,DiZhi.SI,DiZhi.CHEN};
	private static DiZhi[] tianXiBiao = {DiZhi.YOU,DiZhi.SHEN,DiZhi.WEI,DiZhi.WU,DiZhi.SI,DiZhi.CHEN,DiZhi.MAO,DiZhi.YIN,DiZhi.CHOU,DiZhi.ZI,DiZhi.HAI,DiZhi.XU};

	
	/**
	 * 根据生年地支，返回红鸾所在宫支
	 * @param tianGan 生年地支
	 * @return DiZhi
	 */
	public static DiZhi anHongLuan(DiZhi diZhi){
		return hongLuanBiao[diZhi.ordinal()];
	}
	
	/**
	 * 根据生年地支，返回天喜所在宫支
	 * @param tianGan 生年地支
	 * @return DiZhi
	 */
	public static DiZhi anTianXi(DiZhi diZhi){
		return tianXiBiao[diZhi.ordinal()];
	}
	
	/**
	 * 龙池凤阁是两个吉星
	 * 龙池由辰宫起子年，顺数到本人生年的地支
	 * 风格由戌宫起子年，逆数到本人生年的地支
	 */
	private static DiZhi[] longChiBiao = {DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU,DiZhi.YIN,DiZhi.MAO};
	private static DiZhi[] fengGeBiao = {DiZhi.XU,DiZhi.YOU,DiZhi.SHEN,DiZhi.WEI,DiZhi.WU,DiZhi.SI,DiZhi.CHEN,DiZhi.MAO,DiZhi.YIN,DiZhi.CHOU,DiZhi.ZI,DiZhi.HAI};
	
	/**
	 * 根据生年地支，返回龙池所在宫支
	 * @param tianGan 生年地支
	 * @return DiZhi
	 */
	public static DiZhi anLongChi(DiZhi diZhi){
		return longChiBiao[diZhi.ordinal()];
	}
	
	/**
	 * 根据生年地支，返回凤阁所在宫支
	 * @param tianGan 生年地支
	 * @return DiZhi
	 */
	public static DiZhi anFengGe(DiZhi diZhi){
		return fengGeBiao[diZhi.ordinal()];
	}
	
	/**
	 * 天哭由午宫起子年，逆数到本人生年的地支
	 * 天虚由午宫起子年，顺数到本人生年的地支
	 */
	private static DiZhi[] tianKuBiao = {DiZhi.WU,DiZhi.SI,DiZhi.CHEN,DiZhi.MAO,DiZhi.YIN,DiZhi.CHOU,DiZhi.ZI,DiZhi.HAI,DiZhi.XU,DiZhi.YOU,DiZhi.SHEN,DiZhi.WEI};
	private static DiZhi[] tianXuBiao = {DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU,DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN,DiZhi.SI};

	/**
	 * 根据生年地支，返回天哭所在宫支
	 * @param tianGan 生年地支
	 * @return DiZhi
	 */
	public static DiZhi anTianKu(DiZhi diZhi){
		return tianKuBiao[diZhi.ordinal()];
	}
	
	/**
	 * 根据生年地支，返回天虚所在宫支
	 * @param tianGan 生年地支
	 * @return DiZhi
	 */
	public static DiZhi anTianXu(DiZhi diZhi){
		return tianXuBiao[diZhi.ordinal()];
	}
	
	/**
	 * 根据本人生年地支，每三宫一变
	 * 寅卯辰年生人，孤辰在巳，寡宿在丑。
	 * 巳午未年生人，孤辰在申，寡宿在辰。
	 * 申酉戌年生人，孤辰在亥，寡宿在未。
	 * 亥子丑年生人，孤辰在寅，寡宿在戌。
	 * 如乙丑年生人，孤辰排在寅宫，寡宿在戌宫。
	 * 先以[方]中的旺神求冲，如寅卯辰年生人，卯为旺神，卯的六冲在酉。得酉之后，其[局]中余宫即是孤辰寡宿位，酉属[巳酉丑金局]，所以巳宫安孤辰，丑宫安寡宿。
	 * [亥子丑]中[子]冲[午]。[寅午戌]三合，找寅戌安星。
	 */
	private static DiZhi[] guChenBiao = {DiZhi.YIN,DiZhi.YIN,DiZhi.SI,DiZhi.SI,DiZhi.SI,DiZhi.SHEN,DiZhi.SHEN,DiZhi.SHEN,DiZhi.HAI,DiZhi.HAI,DiZhi.HAI,DiZhi.YIN};
	private static DiZhi[] guaSuBiao = {DiZhi.XU,DiZhi.XU,DiZhi.CHOU,DiZhi.CHOU,DiZhi.CHOU,DiZhi.CHEN,DiZhi.CHEN,DiZhi.CHEN,DiZhi.WEI,DiZhi.WEI,DiZhi.WEI,DiZhi.XU};

	/**
	 * 根据生年地支，返回孤辰所在宫支
	 * @param tianGan 生年地支
	 * @return DiZhi
	 */
	public static DiZhi anGuChen(DiZhi diZhi){
		return guChenBiao[diZhi.ordinal()];
	}
	
	/**
	 * 根据生年地支，返回寡宿所在宫支
	 * @param tianGan 生年地支
	 * @return DiZhi
	 */
	public static DiZhi anGuaSu(DiZhi diZhi){
		return guaSuBiao[diZhi.ordinal()];
	}
	
	/**
	 * 华盖子年由辰宫起，按辰丑戌未轮排十二支。
	 * 劫杀以三合局来定位，例如申子辰三合水局，在水局之绝位，即巳位安劫杀，
	 * 故寅午戌三合火局，绝位在亥宫，劫杀在亥。亥卯未三合木局，劫杀在申；巳酉丑
	 * 三合金局，绝位在寅。另可记[简法]，即劫杀必在华盖前一位。
	 */
	private static DiZhi[] huaGaiBiao = {DiZhi.CHEN,DiZhi.CHOU,DiZhi.XU,DiZhi.WEI,DiZhi.CHEN,DiZhi.CHOU,DiZhi.XU,DiZhi.WEI,DiZhi.CHEN,DiZhi.CHOU,DiZhi.XU,DiZhi.WEI};
	private static DiZhi[] jieShaBiao = {DiZhi.SI,DiZhi.YIN,DiZhi.HAI,DiZhi.SHEN,DiZhi.SI,DiZhi.YIN,DiZhi.HAI,DiZhi.SHEN,DiZhi.SI,DiZhi.YIN,DiZhi.HAI,DiZhi.SHEN};
	
	/**
	 * 根据出生年地支，返回华盖所在宫支
	 * @param diZhi 出生年地支
	 * @return DiZhi
	 */
	public static DiZhi anHuaGai(DiZhi diZhi){
		return huaGaiBiao[diZhi.ordinal()];
	}
	
	/**
	 * 根据出生年地支，返回劫煞所在宫支
	 * @param diZhi 出生年地支
	 * @return DiZhi
	 */
	public static DiZhi anJieSha(DiZhi diZhi){
		return jieShaBiao[diZhi.ordinal()];
	}
	
	/**
	 * 咸池即桃花煞
	 * 咸池由酉宫起，按酉午卯子轮排十二支。
	 * 酉午卯子又称四败之地，或四花之地
	 */
	private static DiZhi[] xianChiBiao = {DiZhi.YOU,DiZhi.WU,DiZhi.MAO,DiZhi.ZI,DiZhi.YOU,DiZhi.WU,DiZhi.MAO,DiZhi.ZI,DiZhi.YOU,DiZhi.WU,DiZhi.MAO,DiZhi.ZI};

	
	/**
	 * 根据出生年地支，返回咸池所在宫支
	 * @param diZhi 出生年地支
	 * @return DiZhi
	 */
	public static DiZhi anXianChi(DiZhi diZhi){
		return xianChiBiao[diZhi.ordinal()];
	}
	
	/**
	 * 以生年地支找出子时起点，再顺数至生时即可。
	 * 如丑年生人，火星以卯宫起子时，顺数到卯时，即午宫安火星，铃星从戌宫起子时，顺数到卯时，即丑宫安铃星
	 */
	private static DiZhi[][] huoXingBiao = {{DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU},
			 {DiZhi.MAO,DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU,DiZhi.YIN},
			 {DiZhi.CHOU,DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.ZI},
			 {DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU,DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN}};
	private static DiZhi[][] lingXingBiao = {{DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU,DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU},
			  {DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU,DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU},
			  {DiZhi.MAO,DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU,DiZhi.YIN},
			  {DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU,DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU}};

	
	/**
	 * 根据出生年地支和出生时辰，返回火星所在宫支
	 * @param diZhi 出生年地支
	 * @param shiChen 出生时辰
	 * @return DiZhi
	 */
	public static DiZhi anHuoXing(DiZhi diZhi, DiZhi shiChen){
		return huoXingBiao[diZhi.ordinal()%4][shiChen.ordinal()];
	}
	
	/**
	 * 根据出生年地支和出生时辰，返回火星所在宫支
	 * @param diZhi 出生年地支
	 * @param shiChen 出生时辰
	 * @return DiZhi
	 */
	public static DiZhi anLingXing(DiZhi diZhi, DiZhi shiChen){
		return lingXingBiao[diZhi.ordinal()%4][shiChen.ordinal()];
	}
	
	/**
	 * 天马星又称驿马星
	 * 天马以三合局为准，冲三台长生之宫位，即安天马。如申子辰年生人，长生在申，寅冲申，故此三年生人，天马在寅。
	 * 如丑巳酉年生人，长生在巳，对宫为亥，亥宫安天马。
	 */
	private static DiZhi[] tianMaBiao = {DiZhi.YIN,DiZhi.HAI,DiZhi.SHEN,DiZhi.SI,DiZhi.YIN,DiZhi.HAI,DiZhi.SHEN,DiZhi.SI,DiZhi.YIN,DiZhi.HAI,DiZhi.SHEN,DiZhi.SI};
	
	/**
	 * 根据生年地支，返回天马所在宫支
	 * @param tianGan 生年地支
	 * @return DiZhi
	 */
	public static DiZhi anTianMa(DiZhi diZhi){
		return tianMaBiao[diZhi.ordinal()];
	}
	
	/**
	 * 大耗在生年地支之对宫，前一位或后一位安星。阳支顺行前一位，阴支逆行后一位。
	 * 例如乙丑年生人，丑的对宫为未，丑为阴，逆行一位为午
	 */
	private static DiZhi[] daHaoBiao = {DiZhi.WEI,DiZhi.WU,DiZhi.YOU,DiZhi.SHEN,DiZhi.HAI,DiZhi.XU,DiZhi.CHOU,DiZhi.ZI,DiZhi.MAO,DiZhi.YIN,DiZhi.SI,DiZhi.CHEN};
	
	/**
	 * 根据出生年地支，返回大耗所在宫支
	 * @param diZhi 出生年地支
	 * @return DiZhi
	 */
	public static DiZhi anDaHao(DiZhi diZhi){
		return daHaoBiao[diZhi.ordinal()];
	}
	
	/**
	 * 破碎子年起巳宫，按巳丑酉三合轮排。
	 */
	private static DiZhi[] poSuiBiao = {DiZhi.SI,DiZhi.CHOU,DiZhi.YOU,DiZhi.SI,DiZhi.CHOU,DiZhi.YOU,DiZhi.SI,DiZhi.CHOU,DiZhi.YOU,DiZhi.SI,DiZhi.CHOU,DiZhi.YOU};
	
	/**
	 * 根据出生年地支，返回破碎所在宫支
	 * @param diZhi 出生年地支
	 * @return DiZhi
	 */
	public static DiZhi anPoSui(DiZhi diZhi){
		return poSuiBiao[diZhi.ordinal()];
	}
	
	/**
	 * 天空在出生年地支前一宫，例如午年生人，天空在未宫。
	 */
	private static DiZhi[] tianKongBiao = {DiZhi.CHOU,DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.ZI};
	
	/**
	 * 根据生年地支，返回天空所在宫支
	 * @param tianGan 生年地支
	 * @return DiZhi
	 */
	public static DiZhi anTianKong(DiZhi diZhi){
		return tianKongBiao[diZhi.ordinal()];
	}
	
	/**
	 * 天德由酉宫起子年，顺数到出生年地支，安地支
	 * 解神由戌宫起子年，逆数到出生年地支，安解神
	 */
	private static DiZhi[] tianDeBiao = {DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU,DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN};
	private static DiZhi[] nianJieBiao = {DiZhi.XU,DiZhi.YOU,DiZhi.SHEN,DiZhi.WEI,DiZhi.WU,DiZhi.SI,DiZhi.CHEN,DiZhi.MAO,DiZhi.YIN,DiZhi.CHOU,DiZhi.ZI,DiZhi.HAI};

	/**
	 * 根据出生年地支，返回天德所在宫支
	 * @param diZhi 出生年地支
	 * @return DiZhi
	 */
	public static DiZhi anTianDe(DiZhi diZhi){
		return tianDeBiao[diZhi.ordinal()];
	}
	
	/**
	 * 根据出生年地支，返回年解所在宫支
	 * @param diZhi 出生年地支
	 * @return DiZhi
	 */
	public static DiZhi anNianJie(DiZhi diZhi){
		return nianJieBiao[diZhi.ordinal()];
	}
	
	/**
	 * 十天干，十二地支，所以十天干配十二地支便有两个地支落空，称为旬空，在六十甲子中，便有六个旬空
	 * 依年干年支顺数至癸后二位。
	 * 例如戊午年出生，于午宫起戊，末宫己，申宫庚，酉宫辛，戌宫壬，亥宫癸， 天干至癸止。故旬空在子、丑二宫。
	 * 注意：在两个旬空宫位中，阳年空阳支，阴年空阴支，即阳年干支两旬空星中的阳支为正空，阴支为副空；阴年干支两旬空星中的阴支为正空，阳支为副空。正空力大，逢灾较重，副空力小，逢灾较轻。
	 */
	private static DiZhi[] xunKongXingBiao1 = {DiZhi.XU,DiZhi.SHEN,DiZhi.WU,DiZhi.CHEN,DiZhi.YIN,DiZhi.ZI};
	private static DiZhi[] xunKongXingBiao2 = {DiZhi.HAI,DiZhi.YOU,DiZhi.WEI,DiZhi.SI,DiZhi.MAO,DiZhi.CHOU};
	
	/**
	 * 根据出生年，返回旬空所在宫支
	 * @param year 出生年
	 * @return DiZhi
	 */
	public static DiZhi anXunKong1(int year){
		return xunKongXingBiao1[(year - 4)%60/10];
	}
	
	/**
	 * 根据出生年，返回旬空所在宫支
	 * @param year 出生年
	 * @return DiZhi
	 */
	public static DiZhi anXunKong2(int year){
		return xunKongXingBiao2[(year - 4)%60/10];
	}
	
	private static DiZhi[] yueDeBiao = {DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.SHEN,DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU,DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN};
	private static DiZhi[] feiLianBiao = {DiZhi.SHEN,DiZhi.YOU,DiZhi.XU,DiZhi.SI,DiZhi.WU,DiZhi.WEI,DiZhi.YIN,DiZhi.MAO,DiZhi.CHEN,DiZhi.HAI,DiZhi.ZI,DiZhi.CHOU};

	
	/**
	 * 根据出生年地支，返回月德所在宫支
	 * @param diZhi 出生年地支
	 * @return DiZhi
	 */
	public static DiZhi anYueDe(DiZhi diZhi){
		return yueDeBiao[diZhi.ordinal()];
	}
	
	/**
	 * 根据出生年地支，返回蜚廉所在宫支
	 * @param diZhi 出生年地支
	 * @return DiZhi
	 */
	public static DiZhi anFeiLian(DiZhi diZhi){
		return feiLianBiao[diZhi.ordinal()];
	}
}
